package sample.ui

import androidx.lifecycle.MutableLiveData
import abc.reflect.AESUtils
import com.google.gson.reflect.TypeToken
import zx.tas.model.CKV2Info
import zx.tas.model.GABPanelPlanV2
import kotlinx.coroutines.script.C
import kotlinx.coroutines.script.GComponents
import kotlinx.coroutines.script.tes.FileUtils
import kotlinx.coroutines.script.tes.appDeviceId
import kotlinx.coroutines.script.tes.appSessionIdDiskFile
import kotlinx.coroutines.script.tes.fromJson
import kotlinx.coroutines.script.tes.jsonString
import kotlinx.coroutines.script.tes.readByDisk
import kotlinx.coroutines.script.tes.toast
import kotlinx.coroutines.script.tes.writeToDisk

object Properties {
    private var sId: String? = null
    val sessionId: String? get() {
        return sId ?: (AESUtils.decrypt("n${appDeviceId}${ckV2Info?.value}", readByDisk("csi") ?:"")).also { sId = it }
    }
    fun setSessionId(value: String) {
        sId = value
    }
    private var ckv2: CKV2Info?= null
    val ckV2Info: CKV2Info? get() {
        if (ckv2 != null) return ckv2
        var disk = readByDisk("ckV2Info")
        if (disk.isNullOrEmpty()) disk = FileUtils.syncRead(appSessionIdDiskFile)
        return (fromJson(disk, CKV2Info::class.java).also { ckv2 = it })
    }
    fun setCKV2Info(value: CKV2Info?) {
        ckv2 = value
        writeToDisk("ckV2Info", value?.jsonString)
        FileUtils.syncWrite(appSessionIdDiskFile, value?.jsonString ?: "")
    }

    val isSettingsOk = MutableLiveData<Boolean>()
    val isSettingsCompleted get() = isSettingsOk.value ?: false

    private var are: String? = null
    val area: String get() {
        return are ?: (readByDisk("av") ?: "").also { are = it }
    }
    private fun setArea(value: String?) {
        are = value
        writeToDisk("av", value)
    }
    private var cav2List: List<String>? = null
    // 已经选中的列表
    val selectedChildAreaList: List<String> get() {
        return cav2List ?: (fromJson(readByDisk("cav2List"), object : TypeToken<List<String>>(){}.type) ?: listOf<String>()).also { cav2List = it }
    }
    private fun setSelectedChildArea(value: List<String>?) {
        cav2List = value
        writeToDisk("cav2List", value?.jsonString)
    }

    private var scen: String? = null
    val scene: String get() {
        return scen ?: (readByDisk("sv") ?: "").also { scen = it }
    }
    private fun setScene(value: String?) {
        scen = value
        writeToDisk("sv", value)
    }
//    private var cst: String? = null
//    val castle: String get() {
//        return cst ?: (readByDisk("cst") ?: "").also { cst = it }
//    }
//    private fun setCastle(value: String?) {
//        cst = value
//        writeToDisk("cst", value)
//    }
//    private var fs: String? = null
//    val fishing: String get() {
//        return fs ?: (readByDisk("fs") ?: "").also { fs = it }
//    }
//    private fun setFishing(value: String?) {
//        fs = value
//        writeToDisk("fs", value)
//    }

    fun setTask(scene: String?,  a: String?, childArea: List<String>?, ) {
        if (area.isEmpty() && a?.isNotEmpty() == true) {
            GComponents.clearGoDisk()
            toast("副本切换到打野已自动清除缓存")
        }

        setScene(scene)
//        setCastle(castle)
        setArea(a)
        setSelectedChildArea(childArea)
//        setFishing(fishing)
        notifySettingsOk()


    }

//    private var fpa: Int? = null
//    @Deprecated("") val fixedPointAngle: Int get() {
//        return fpa ?: (readByDisk("fpa")?.toIntOrNull() ?: 90).also { fpa = it }
//    }
//
//    @Deprecated("") fun setFixedPointAngle(value: Int) {
//        fpa = abs(value) % 360
//        writeToDisk("fpa", fpa.toString())
//    }

    private var swcui: Int? = null
    val sweepingClearUpInterval: Int get() {
        return swcui ?: (readByDisk("swcui")?.toIntOrNull() ?: 10).also { swcui = it }
    }
    fun setSweepingClearUpInterval(value: Int) {
        swcui = value
        writeToDisk("swcui", value.toString())
    }

    private var spcui: Int? = null
    val sweepingPetClearUpInterval get() = spcui ?: (readByDisk("spcui")?.toIntOrNull() ?: 0).also { spcui = it }
    fun setSweepingPetClearUpInterval(value: Int) {
        spcui = value
        writeToDisk("spcui", value.toString())
    }

    private var sfbsp: Int? = null
    val sweepingForceBlacksmithPosition get() = sfbsp ?: (readByDisk("sfbsp")?.toIntOrNull() ?: 0).also { sfbsp = it }
    fun setSweepingForceBlacksmithPosition(value: Int) {
        sfbsp = value
        writeToDisk("sfbsp", value.toString())
    }

    private var cudae2: Boolean? = null
    val clearUpDoArrowEquip: Boolean get() {
        return cudae2 ?: (readByDisk("cudae2")?.toBooleanStrictOrNull() ?: false).also { cudae2 = it }
    }
    fun setClearUpDoArrowEquip(value: Boolean) {
        cudae2 = value
        writeToDisk("cudae2", value.toString())
    }

    private var fcui: Int? = null
    val fishingOverTs: Int get() {
        return fcui ?: (readByDisk("fcui")?.toIntOrNull() ?: 50).also { fcui = it }
    }
    fun setFishingOverTs(value: Int) {
        fcui = value
        writeToDisk("fcui", value.toString())
    }

    private var flv: Int? = null
    val fishingLv: Int get() {
        return flv ?: (readByDisk("flv")?.toIntOrNull() ?: 3).also { flv = it }
    }
    fun setFishingLv(value: Int) {
        flv = value
        writeToDisk("flv", value.toString())
    }
    private var fArea: String? = null
    val fishingArea: String get() {
        return fArea ?: (readByDisk("fArea") ?: C.F_AREA_BRFD).also { fArea = it }
    }
    fun setFishingArea(value: String?) {
        fArea = value
        writeToDisk("fArea", value)
    }

    private var sceneCui: Int? = null
    val sceneClearUpInterval: Int get() {
        return sceneCui ?: (readByDisk("sceneCui")?.toIntOrNull() ?: 1).also { sceneCui = it }
    }
    fun setSceneClearUpInterval(value: Int) {
        sceneCui = value
        writeToDisk("sceneCui", value.toString())
    }

//    private var sceneGUT: Int? = null
//    val sceneGiveUpTime: Int get() {
//        return sceneGUT ?: (readByDisk("sceneGUT")?.toIntOrNull() ?: 600).also { sceneGUT = it }
//    }
//    fun setSceneGiveUpTime(value: Int) {
//        sceneGUT = value
//        writeToDisk("sceneGUT", value.toString())
//    }
//    private var sceneGUE: Int? = null
//    val sceneGiveUpEnemy: Int get() {
//        return sceneGUE ?: (readByDisk("sceneGUE")?.toIntOrNull() ?: 3).also { sceneGUE = it }
//    }
//    fun setSceneGiveUpEnemy(value: Int) {
//        sceneGUE = value
//        writeToDisk("sceneGUE", value.toString())
//    }
    private var sceneCW: Int? = null
    val sceneContinueWait: Int get() {
        return sceneCW ?: (readByDisk("sceneCW2")?.toIntOrNull() ?: 2).also { sceneCW = it }
    }
    fun setSceneContinueWait(value: Int) {
        sceneCW = value
        writeToDisk("sceneCW2", value.toString())
    }

    private var sLd: Int? = null
    @Deprecated("") val sceneLeader: Int get() { // 0 单人. 1组队队长. 2组队队员
        return sLd ?: (readByDisk("sLd")?.toIntOrNull() ?: 0).also { sLd = it }
    }
    fun setSceneLeader(value: Int) {
        sLd = value
        writeToDisk("sLd", value.toString())
    }

    private var sJLp1: Int? = null
    val sceneJLP1: Int get() { // 0 全清. 1跳过
        return sJLp1 ?: (readByDisk("sJLp1")?.toIntOrNull() ?: 1).also { sJLp1 = it }
    }
    fun setSceneJLP1(value: Int) {
        sJLp1 = value
        writeToDisk("sJLp1", value.toString())
    }
    private var sJLp2: Int? = null
    val sceneJLP2: Int get() { // 0 全清. 1跳过
        // val default = if (profession == C.P_SLFS) 1 else 0
        return sJLp2 ?: (readByDisk("sJLp2")?.toIntOrNull() ?: 1).also { sJLp2 = it }
    }
    fun setSceneJLP2(value: Int) {
        sJLp2 = value
        writeToDisk("sJLp2", value.toString())
    }

    private var sJLp1Atk: Int? = null
    val sceneJLP1Atk: Int get() { // 每x次触发一次普攻
        return sJLp1Atk ?: (readByDisk("sJLp1Atk")?.toIntOrNull() ?: 0).also { sJLp1Atk = it }
    }
    fun setSceneJLP1Atk(value: Int) {
        sJLp1Atk = value
        writeToDisk("sJLp1Atk", value.toString())
    }

    private var sJLBossAtkMode: Int? = null
    val sceneJLBossAtkMode: Int get() { // 每x次触发一次普攻
        return sJLBossAtkMode ?: (readByDisk("sJLBossAtkMode")?.toIntOrNull() ?: 0).also { sJLBossAtkMode = it }
    }
    fun setSceneJLBossAtkMode(value: Int) {
        sJLBossAtkMode = value
        writeToDisk("sJLBossAtkMode", value.toString())
    }

    private var smp: Boolean? = null
    @Deprecated("") val sweepingMapPoint: Boolean get() {
        return smp ?: (readByDisk("smp")?.toBooleanStrictOrNull() ?: false).also { smp = it }
    }
    @Deprecated("") fun setSweepingMapPoint(value: Boolean) {
        smp = value
        writeToDisk("smp", value.toString())
    }

    private var ate: Boolean? = null
    val activelyToElite: Boolean get() {
        return ate ?: (readByDisk("ate")?.toBooleanStrictOrNull() ?: true).also { ate = it }
    }
    fun setActivelyToElite(value: Boolean) {
        ate = value
        writeToDisk("ate", value.toString())
    }

    private var fpd: Int? = null
    @Deprecated("") val fixedPointDistance: Int get() {
        return fpd ?: (readByDisk("fpd")?.toIntOrNull() ?: 50).also { fpd = it }
    }
    @Deprecated("")fun setFixedPointDistance(value: Int) {
        fpd = value
        writeToDisk("fpd", value.toString())
    }

    private var sc: Int? = null
    val stopCountdown: Int get() {
        return sc ?: (readByDisk("sc")?.toIntOrNull() ?: 0).also { sc = it }
    }
    fun setStopCountdown(value: Int) {
        sc = value
        writeToDisk("sc", value.toString())
    }

    private var nrc: Int? = null
    val netRetryCount: Int get() {
        return nrc ?: (readByDisk("netRcV2")?.toIntOrNull() ?: 20).also { nrc = it }
    }
    fun setNetRetryCount(value: Int) {
        nrc = value
        writeToDisk("netRcV2", value.toString())
    }

    private var castleSP2: Int? = null
    val castleStopPoint: Int get() {
        return castleSP2 ?: (readByDisk("castleSP2")?.toIntOrNull() ?: 15000).also { castleSP2 = it }
    }
    fun setCastleStopPoint(value: Int) {
        castleSP2 = value
        writeToDisk("castleSP2", value.toString())
    }
    private var castleST2: Int? = null
    val castleStopTime: Int get() {
        return castleST2 ?: (readByDisk("castleST4")?.toIntOrNull() ?: 1210).also { castleST2 = it }
    }
    fun setCastleStopTime(value: Int) {
        castleST2 = value
        writeToDisk("castleST4", value.toString())
    }

    private var castleGUT: Int? = null
    val castleGiveUpType: Int get() { //1冲毒 . 0大门
        return castleGUT ?: (readByDisk("castleGUT")?.toIntOrNull() ?: 1).also { castleGUT = it }
    }
    fun setCastleGiveUpType(value: Int) {
        castleGUT = value
        writeToDisk("castleGUT", value.toString())
    }

    private var castleCui: Int? = null
    val castleClearUpInterval: Int get() {
        return castleCui ?: (readByDisk("castleCui")?.toIntOrNull() ?: 0).also { castleCui = it }
    }
    fun setCastleClearUpInterval(value: Int) {
        castleCui = value
        writeToDisk("castleCui", value.toString())
    }
    private var scene4Box: Boolean? = null
    val sceneBossBox: Boolean get() {
        return scene4Box ?: (readByDisk("scene4Box")?.toBooleanStrictOrNull() ?: false).also { scene4Box = it }
    }
    fun setSceneBossBox(value: Boolean) {
        scene4Box = value
        writeToDisk("scene4Box", value.toString())
    }

    private var shyrtbdt: Int? = null
    val sceneHYReviveToBlueDoorTime: Int get() {
        return shyrtbdt ?: (readByDisk("shyrtbdt")?.toIntOrNull() ?: 1600).also { shyrtbdt = it }
    }
    fun setSceneHYReviveToBlueDoorTime(value: Int) {
        shyrtbdt = value
        writeToDisk("shyrtbdt", value.toString())
    }
    private var shyrtbda: Int? = null
    val sceneHYReviveToBlueDoorAngle: Int get() {
        return shyrtbda ?: (readByDisk("shyrtbda")?.toIntOrNull() ?: 62).also { shyrtbda = it }
    }
    fun setSceneHYReviveToBlueDoorAngle(value: Int) {
        shyrtbda = value
        writeToDisk("shyrtbda", value.toString())
    }


    private var ikp: Int? = null
    val immKeyPos: Int get() {
        return ikp ?: (readByDisk("ikp")?.toIntOrNull() ?: 7).also { ikp = it }
    }
    fun setImmKeyPos(value: Int) {
        ikp = value
        writeToDisk("ikp", value.toString())
    }

    private var lxep: Int? = null
    fun setLxEnterPos(value: Int) {
        lxep = value
        writeToDisk("lxep", value.toString())
    }
    val lxEnterPos: Int get() {
        return lxep ?: (readByDisk("lxep")?.toIntOrNull() ?: 0).also { lxep = it }
    }

    private var fsm: Int? = null
    val forceSceneMode: Int get() {
        return fsm ?: (readByDisk("fsm")?.toIntOrNull() ?: 1).also { fsm = it }
    }
    fun setForceSceneMode(value: Int) {
        fsm = value
        writeToDisk("fsm", value.toString())
    }

    private var dl2: Boolean? = null
    val displayLog: Boolean get() {
        return dl2 ?: (readByDisk("dl3")?.toBooleanStrictOrNull() ?: false).also { dl2 = it }
    }
    fun setDisplayLog(value: Boolean) {
        dl2 = value
        writeToDisk("dl3", value.toString())
    }
    private var dt2: Boolean? = null
    val displayToast: Boolean get() {
        return dt2 ?: (readByDisk("dt3")?.toBooleanStrictOrNull() ?: false).also { dt2 = it }
    }
    fun setDisplayToast(value: Boolean) {
        dt2 = value
        writeToDisk("dt3", value.toString())
    }

    private var usc: String? = null
    val usingSkillChain: String get() {
        return usc ?: (readByDisk("usc") ?: "").also { usc = it }
    }
    fun setUsingSkillChain(value: String?) {
        usc = value
        writeToDisk("usc", value)
        notifySettingsOk()
    }

    private var arow: Int? = null
    val appReopenWait: Int get() {
        return arow ?: (readByDisk("arow")?.toIntOrNull() ?: 60).also { arow = it }
    }
    fun setAppReopenWait(value: Int) {
        arow = value
        writeToDisk("arow", value.toString())
    }

    private var p: String? = null
    val profession: String get() {
        return p ?: (readByDisk("pf") ?: "").also { p = it }
    }
    fun setProfession(value: String?) {
        p = value
        writeToDisk("pf", value)
        notifySettingsOk()
    }

//    private var ap3: String? = null
//    val autoPick: String get() {
//        return ap3 ?: (readByDisk("ap3") ?: "WBY").also { ap3 = it }
//    }
//    fun setAutoPick(value: String?) {
//        ap3 = value
//        writeToDisk("ap3", value.toString())
//    }


    private var um: Int? = null
    val useMedicine: Int get() {
        return um ?: (readByDisk("um")?.toIntOrNull() ?: 74).also { um = it }
    }
    fun setUseMedicine(value: Int) {
        um = value
        writeToDisk("um", value.toString())
    }

    private var cr: Boolean? = null
    val isControllerRunning: Boolean get() {
        return cr ?: (readByDisk("cr")?.toBooleanStrictOrNull() ?: false).also { cr = it }
    }
    fun setControllerRunning(value: Boolean) {
        cr = value
        writeToDisk("cr", value.toString())
    }

    private var sh: Int? = null
    val usingScreenHeight: Int get() {
        return sh ?: (readByDisk("ush")?.toIntOrNull() ?: -1).also { sh = it }
    }
    fun setUsingScreenHeight(value: Int) {
        sh = value
        writeToDisk("ush", value.toString())
    }
    private var sw: Int? = null
    val usingScreenWidth: Int get() {
        return sw ?: (readByDisk("usw")?.toIntOrNull() ?: -1).also { sw = it }
    }
    fun setUsingScreenWidth(value: Int) {
        sw = value
        writeToDisk("usw", value.toString())
    }

//    private var kebd: Int? = null
//    val keepEnemyBodyDistance: Int get() {
//        return kebd ?: (readByDisk("kebd")?.toIntOrNull() ?: 260).also { kebd = it }
//    }
//    fun setKeepEnemyBodyDistance(value: Int) {
//        kebd = value
//        writeToDisk("kebd", value.toString())
//    }

    private var kemdV2: Int? = null
    val keepEnemySMapDistance: Int get() {
        return kemdV2 ?: (readByDisk("kemdV3")?.toIntOrNull() ?: 0).also { kemdV2 = it }
    }
    fun setKeepEnemySMapDistance(value: Int) {
        kemdV2 = value
        writeToDisk("kemdV3", value.toString())
    }

    private var srm: Boolean? = null
    val skipRandomMode: Boolean get() {
        return srm ?: (readByDisk("srm")?.toBooleanStrictOrNull() ?: false).also { srm = it }
    }
    fun setSkipRandomMode(value: Boolean) {
        srm = value
        writeToDisk("srm", value.toString())
    }

    private var rs: Int? = null
    val roleSpeed: Int get() {
        return rs ?: (readByDisk("rsV5")?.toIntOrNull() ?: 111).also { rs = it }
    }
    fun setRoleSpeed(value: Int) {
        rs = value
        writeToDisk("rsV5", value.toString())
    }


    private var iaa: Int? = null
    // [废弃] 0.全部拒绝.1.同意并加白内容.2为同意白名单内容 (废)
    // [废弃] 0.全部拒绝.3 全部同意
    // 0.全部拒绝.  1.开局收录+指定名单. 2仅指定名单. 3全部同意
    val inviteAutoAccept: Int get() {
        return iaa ?: (readByDisk("iaa4")?.toIntOrNull() ?: 0).also { iaa = it }
    }
    fun setInviteAutoAccept(value: Int) {
        iaa = value
        writeToDisk("iaa4", value.toString())
    }

    private var rli: Boolean? = null
    val recordLogImage: Boolean get() {
        return rli ?: (readByDisk("rli")?.toBooleanStrictOrNull() ?: false).also { rli = it }
    }
    fun setRecordLogImage(value: Boolean) {
        rli = value
        writeToDisk("rli", value.toString())
    }

    private var usf800: Boolean? = null
    val useSkillF800: Boolean get() {
        return usf800 ?: (readByDisk("usf800")?.toBooleanStrictOrNull() ?: false).also { usf800 = it }
    }
    fun setUseSkillF800(value: Boolean) {
        usf800 = value
        writeToDisk("usf800", value.toString())
    }

    private var scbw: Int? = null
    fun setSceneClearBlueDoorWait(value: Int) {
        scbw = value
        writeToDisk("scbw", value.toString())
    }
    val sceneClearBlueDoorWait: Int get() {
        return scbw ?: (readByDisk("scbw")?.toIntOrNull() ?: 0).also { scbw = it }
    }

    private var ssto: Int? = null
    val scriptStopTimeout: Int get() = ssto ?: (readByDisk("sstoV5")?.toIntOrNull() ?: 900).also { ssto = it }
    fun setScriptStopTimeout(value: Int) {
        ssto = value
        writeToDisk("sstoV5", value.toString())
    }

    private var siii: Boolean? = null
    val sweepingIgnoreInteractItem: Boolean get() = siii ?: (readByDisk("siii")?.toBooleanStrictOrNull() ?: false).also { siii = it }
    fun setSweepingIgnoreInteractItem(value: Boolean) {
        siii = value
        writeToDisk("siii", value.toString())
    }

    private var tlac: Boolean? = null
    val tryLaunchAfterUnknown: Boolean get() = tlac ?: (readByDisk("tlac")?.toBooleanStrictOrNull() ?: true).also { tlac = it }
    fun setTryLaunchAfterUnknown(value: Boolean) {
        tlac = value
        writeToDisk("tlac", value.toString())
    }

    private var cfbp: Boolean? = null
    val checkFullBackpack: Boolean get() = cfbp ?: (readByDisk("cfbp")?.toBooleanStrictOrNull() ?: false).also { cfbp = it }
    fun setCheckFullBackpack(value: Boolean) {
        cfbp = value
        writeToDisk("cfbp", value.toString())
    }

    private var spc: Boolean? = null
    val scenePetClear: Boolean get() = spc ?: (readByDisk("spc")?.toBooleanStrictOrNull() ?: false).also { spc = it }
    fun setScenePetClear(value: Boolean) {
        spc = value
        writeToDisk("spc", value.toString())
    }
    private var ss8: Boolean? = null
    val sceneSkill800: Boolean get() = ss8 ?: (readByDisk("ss8")?.toBooleanStrictOrNull() ?: false).also { ss8 = it }
    fun setSceneSkill800(value: Boolean) {
        ss8 = value
        writeToDisk("ss8", value.toString())
    }

    private var qczz: Boolean? = null // 启程之章
    val playerQCZZ: Boolean get() = qczz ?: (readByDisk("qczz")?.toBooleanStrictOrNull() ?: true).also { qczz = it }
    fun setPlayerQCZZ(value: Boolean) {
        qczz = value
        writeToDisk("qczz", value.toString())
    }



    private var rfi: Int? = null
    val refreshFrameInterval: Int get() = rfi ?: (readByDisk("rfi")?.toIntOrNull() ?: 400).also { rfi = it }
    fun setRefreshFrameInterval(value: Int) {
        rfi = value
        writeToDisk("rfi", value.toString())
    }


    private var gabPlan: GABPanelPlanV2? = null
    val gabPanelPlan: GABPanelPlanV2
        get() { // 把默认2个字消掉
        return gabPlan ?: (fromJson(readByDisk("gabPlanV17"), GABPanelPlanV2::class.java) ?: GABPanelPlanV2.fast).also { gabPlan = it }
    }
    fun setGabPanelPlan(value: GABPanelPlanV2) {
        gabPlan = value
        writeToDisk("gabPlanV17", value.jsonString)
    }

    private var ssi: Int? = null
    val scriptSleepInterval get() = ssi ?: (readByDisk("ssi3")?.toIntOrNull() ?: 0).also { ssi = it }
    fun setScriptSleepInterval(value: Int) {
        ssi = value
        writeToDisk("ssi3", value.toString())
    }
    private var ssu: Float? = null
    val scriptSleepUnitTs get() = ssu ?: (readByDisk("ssu3")?.toFloatOrNull() ?: 0f).also { ssu = it }
    fun setScriptSleepUnitTs(value: Float) {
        ssu = value
        writeToDisk("ssu3", value.toString())
    }
    private var ssai: Float? = null
    val scriptSleepAtkInterval get() = ssai ?: (readByDisk("ssai")?.toFloatOrNull() ?: 0.4f).also { ssai = it }
    fun setScriptSleepAtkInterval(value: Float) {
        ssai = value
        writeToDisk("ssai", value.toString())
    }

    private var una: Boolean? = null
    val useNpcAssist get() = una ?: (readByDisk("una2")?.toBooleanStrictOrNull() ?: true).also { una = it }
    fun setUseNpcAssist(value: Boolean) {
        una = value
        writeToDisk("una2", value.toString())
    }

    private var adyc: Long? = null
    // 打野续时间间隔
    val autoDYContinueTime: Long get() = adyc ?: (readByDisk("adycV4")?.toLongOrNull() ?: 1740000L).also { adyc = it }
    fun setAutoDYContinueTime(value: Long) {
        adyc = value
        writeToDisk("adycV4", value.toString())
    }

    private var dyzze: Int? = null
    val dyZZEdge get() = dyzze ?: (readByDisk("dyzze")?.toIntOrNull() ?: 0).also { dyzze = it }
    fun setDYZZEdge(value: Int) {
        dyzze = value
        writeToDisk("dyzze", value.toString())
    }

    private var irt: Int? = null
    val immRestart get() = irt ?: (readByDisk("irt")?.toIntOrNull() ?: 0).also { irt = it }
    fun setImmRestart(value: Int) {
        irt = value
        writeToDisk("irt", value.toString())
    }

    private fun notifySettingsOk() {
        val s1 = area.isNotEmpty() && selectedChildAreaList.isNotEmpty()
        val s2 = scene.isNotEmpty()
//        val sc = usingSkillChain.isNotEmpty()
//        val c = castle.isNotEmpty()
//        val f = fishing.isNotEmpty()
        isSettingsOk.postValue((s1 || s2 ) // || c || f
//                && sc
        )
    }




    init {
        notifySettingsOk()
    }
}
